package dao.impl;



import entity.Dictionary;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import util.JdbcUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author lyr
 * @create 2020/1/12 21:01
 */
public class MapDaoImpl implements Dao {
    private QueryRunner runner = new QueryRunner();
    private static final String GET_KEY="select `value` from `map-for-wechat` where `key` like ?";
    private static final String ADD_ONE = "insert into `map-for-wechat` values(null,?,?)";
    private static final BeanListHandler<Dictionary> VALUE_HANDLER = new BeanListHandler(Dictionary.class);
    private static final BeanHandler<String> BEAN_HANDLER = new BeanHandler<String>(String.class);
    @Override
    public List<Dictionary> selectValue(String k) throws SQLException {
        return runner.query(JdbcUtil.getConnection(),GET_KEY,VALUE_HANDLER,"%"+k+"%");
    }

    @Override
    public void insertValue(String k, String v) throws SQLException {
         runner.insert(JdbcUtil.getConnection(),ADD_ONE,BEAN_HANDLER,k,v);
    }
}
